import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  mode: 'history',
  routes: [
    {
      path: '/download',
      component: resolve => require(['./pages/download'], resolve)
    },
    {
      path: '/chat',
      component: resolve => require(['./pages/chatBySales'], resolve)
    },
    {
      path: '/login',
      component: resolve => require(['page/login'], resolve)
    },
    {
      path: '/loading',
      component: resolve => require(['page/loading'], resolve)
    },
    {
      path: '/register',
      component: resolve => require(['page/register'], resolve)
    },
    {
      path: '/forget',
      component: resolve => require(['page/forget'], resolve)
    },
    // 中金支付iframe
    {
      path: '/payIframe',
      component: resolve => require(['page/payIframe'], resolve)
    },
    // 下载
    {
      path: '/chooseTerminal',
      component: resolve => require(['page/download'], resolve)
    },
    {
      path: '/',
      component: resolve => require(['./App'], resolve),
      children: [
        {
          path: '/',
          component: resolve => require(['page/index'], resolve)
        },
        {
          path: 'index/:chId',
          component: resolve => require(['page/index'], resolve)
        },
        {
          path: 'payment',
          meta: {isAuth: true},
          component: resolve => require(['page/payment'], resolve)
        },
        // 支付宝，微信二维码
        {
          path: 'qrCode',
          meta: {isAuth: true},
          component: resolve => require(['page/qrCode'], resolve)
        },
        // 支付成功页面
        {
          path: 'notify',
          meta: {isAuth: true},
          component: resolve => require(['page/paySuccess'], resolve)
        },
        // 支付失败页面
        {
          path: 'payFail',
          meta: {isAuth: true},
          component: resolve => require(['page/payFail'], resolve)
        },
        {
          path: 'cart',
          meta: {isAuth: true},
          component: resolve => require(['page/cart'], resolve)
        },
        {
          path: 'placeorder',
          meta: {isAuth: true},
          component: resolve => require(['page/placeOrder'], resolve)
        },
        {
          path: 'my',
          component: resolve => require(['page/my'], resolve),
          children: [
            {
              path: 'order',
              meta: {isAuth: true},
              component: resolve => require(['page/my/myOrder'], resolve)
            },
            // 增值服务
            {
              path: 'extra',
              meta: {isAuth: true},
              component: resolve => require(['page/my/extraIndex'], resolve),
              children: [
                // 申请入驻商家
                {
                  path: 'application',
                  component: resolve => require(['page/my/application'], resolve)
                },
                // 支付服务费
                {
                  path: 'pay',
                  meta: {isAuth: true},
                  component: resolve => require(['page/my/payExtra'], resolve)
                },
                {
                  path: 'paysuccess',
                  component: resolve => require(['page/my/paySuccess'], resolve)
                },
                {
                  path: '/',
                  meta: {isAuth: true},
                  component: resolve => require(['page/my/showExtraInfo'], resolve)
                }
              ]
            },
            {
              path: 'collectionstore',
              meta: {isAuth: true},
              component: resolve => require(['page/my/collectionStore'], resolve)
            },
            {
              path: 'collectionshop',
              meta: {isAuth: true},
              component: resolve => require(['page/my/collectionShop'], resolve)
            },
            // 个人信息管理
            {
              path: 'personinfo',
              meta: {isAuth: true},
              component: resolve => require(['page/my/personInfo'], resolve)
            },
            // 地址管理
            {
              path: 'addressmanager',
              meta: {isAuth: true},
              component: resolve => require(['page/my/addressManager'], resolve)
            },
            // 新建地址
            {
              path: 'newaddress',
              meta: {isAuth: true},
              component: resolve => require(['page/my/newAddress'], resolve)
            },
            // 修改密码
            {
              path: 'updatepassword',
              meta: {isAuth: true},
              component: resolve => require(['page/my/updatePassword'], resolve)
            },
            // 退款管理
            {
              path: 'refund',
              meta: {isAuth: true},
              component: resolve => require(['page/my/refund'], resolve)
            },
            // 我的足迹
            {
              path: 'tracks',
              meta: {isAuth: true},
              component: resolve => require(['page/my/tracks'], resolve)
            },
            // 消息
            {
              path: 'message',
              meta: {isAuth: true},
              component: resolve => require(['page/my/message'], resolve)
            }
          ]
        },
        // 退款、退货，换货页
        {
          path: 'reindex/:orderid/:carid',
          meta: {isAuth: true},
          component: resolve => require(['page/my/refundIndex'], resolve)
        },
        // 退款退货页
        {
          path: 'repay/:type',
          component: resolve => require(['page/my/refundPay'], resolve)
        },
        // 换货页
        {
          path: 'regoods',
          component: resolve => require(['page/my/refundGoods'], resolve)
        },
        {
          path: 'orderdetail',
          component: resolve => require(['page/my/orderDetail'], resolve)
        },
        // 帮助中心
        {
          path: 'helpCenter',
          component: resolve => require(['page/helpCenter'], resolve),
          children: [
            {
              path: '/helpCenter/:title',
              component: resolve => require(['page/helpCenter'], resolve)
            }
          ]
        },
        // 订单评价
        {
          path: 'orderevaluate',
          meta: {isAuth: true},
          component: resolve => require(['page/my/orderEvaluate'], resolve)
        },
        // 商品详情页restful风格，最后的是商品id
        {
          path: 'goods/detail/:id',
          component: resolve => require(['page/goods/detail'], resolve)
        },
        {
          path: 'search',
          component: resolve => require(['page/search/index'], resolve),
          children: [
            {
              path: '/',
              component: resolve => require(['page/search/goodsSearch'], resolve)
            },
            {
              path: 'goods',
              component: resolve => require(['page/search/goodsSearch'], resolve)
            },
            {
              path: 'goodsLists',
              component: resolve => require(['page/search/goodsLists'], resolve)
            },
            {
              path: 'goods/:id',
              component: resolve => require(['page/search/goodsSearch'], resolve)
            },
            {
              path: 'stores/',
              component: resolve => require(['page/search/storeSearch'], resolve)
            },
            {
              path: 'stores/:id',
              component: resolve => require(['page/search/storeSearch'], resolve)
            }
          ]
        },
        // 商家店铺
        {
          path: 'shop/:id',
          component: resolve => require(['page/shop'], resolve),
          children: [
            {
              path: '/',
              component: resolve => require(['page/shop/home'], resolve)
            },
            {
              path: 'type',
              component: resolve => require(['page/shop/list'], resolve)
            },
            {
              path: 'about',
              component: resolve => require(['page/shop/about'], resolve)
            }
          ]
        },
        {
          path: 'loan/apply/:price/:orderId/:mainId',
          component: resolve => require(['page/loan/apply'], resolve)
        },
        {
          path: 'loan/success',
          component: resolve => require(['page/loan/success'], resolve)
        },
        // 回执账单
        {
          path: 'receipt',
          component: resolve => require(['page/receipt'], resolve)
        }
      ]
    },
    {
      path: '/pay/weixin',
      component: resolve => require(['page/pay/weixin'], resolve)
    },
    {
      path: '/pay/zhifubao',
      component: resolve => require(['page/pay/zhifubao'], resolve)
    },
    {
      path: '/pay/shanghu',
      component: resolve => require(['page/pay/shanghu'], resolve)
    }
  ]
})
